<%--
  Created by IntelliJ IDEA.
  User: 16398
  Date: 2020/7/15
  Time: 13:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <title>首页</title>
     <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="attendance/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/commonly-used-show.css" />
    <script type="text/javascript" src="attendance/js/jquery.min.js"></script>
    <script type="text/javascript" src="attendance/js/bootstrap.js" ></script>

</head>
<body class="mybody">

<jsp:include page="theTopMenuUser.jsp" />


<div class="container-fluid">
    <div class="row">
        <div class="col-md-2">
            <div class="text-center" id="left-content">
                <div class="list-group">
                    <a href="#" class="list-group-item active">首页</a>
                </div>
                <div class="list-group">
                    <a href="${pageContext.request.contextPath}/joinNewCourse" class="list-group-item">选择课程</a>
                    <a href="${pageContext.request.contextPath}/curriculumProvision" class="list-group-item">课程管理</a>

                </div>
                <div class="list-group">
                    <a href="${pageContext.request.contextPath}/assistance" class="list-group-item">留言与联系</a>
                </div>
            </div>
        </div>


        <div class="col-md-10">
            <div class="page-header">
                <h1 style="font-size: 18px">我选择的课程</h1>
            </div>

            <div class="row" id="take_course">

            </div>

        </div>

    </div>

</div>


<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }


    window.onload = function(){
        courseAllInfo();
    }


    function courseAllInfo(){
        var postUrl = "${pageContext.request.contextPath}/member/queryStudentCourseInfoAll";

        var str = {
            "studentId": userdt.result.id,
            "selectedState": "1"
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    noDate();
                }else {
                    var strtab = "";
                    var jumpUrl = "";
                    var imgUrl = "";
                    if (data.result.length !== 0){
                        for (var i = 0; i < data.result.length; i++){
                            jumpUrl = "${pageContext.request.contextPath}/myCourse?id=" + data.result[i].id;

                            if (data.result[i].classPictures != null){
                                imgUrl = "${pageContext.request.contextPath}" + data.result[i].classPictures;
                            }else {
                                imgUrl = "attendance/img/no_date.jpeg";
                            }

                            strtab = "<div class=\"col-md-3\">\n" +
                                "                    <div class=\"panel panel-primary\">\n" +
                                "                        <div style=\"margin: 10px\">\n" +
                                "                            <a href='" + jumpUrl + "'><img src='" + imgUrl + "' width=\"235px\" height=\"270px\"></a>\n" +
                                "                            <div style=\"margin-left: 5px; margin-top: 5px\">\n" +
                                "                                <p style=\"font-size: 16px\">" + data.result[i].courseTitle + "</p>\n" +
                                "                                <p style=\"font-size: 14px\">" + data.result[i].instructor + "</p>\n" +
                                "                            </div>\n" +
                                "                        </div>\n" +
                                "                    </div>\n" +
                                "                </div>";
                            $("#take_course").append(strtab);
                        }
                    }else {
                       noDate();
                    }
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

    function noDate(){
        var strtably = "";
        strtably = "<div class=\"col-md-3\">\n" +
            "                    <div class=\"panel panel-primary\">\n" +
            "                        <div style=\"margin: 10px\">\n" +
            "                            <a href=\"#\"><img src=\"attendance/img/no_date.jpeg\" width=\"230px\" height=\"270px\"></a>\n" +
            "                            <div style=\"margin-left: 5px; margin-top: 5px;  margin-bottom: 25px;\">\n" +
            "                                <p style=\"font-size: 16px\">暂无数据</p>\n" +
            "                                <span style=\"font-size: 14px\">暂无数据</span>\n" +
            "                                <button id='mybut' style=\"float: right;\" class=\"btn btn-success\">暂无数据</button>\n" +
            "                            </div>\n" +
            "                        </div>\n" +
            "                    </div>\n" +
            "                </div>";
        $("#take_course").append(strtably);
    }

</script>

</body>
</html>
</span>